﻿/** jquery  dialog插件  janchie  2009

    版本：1.0
*/

(function ($) {
    $.dialog = function (width, height, content, clk) {

        //插入弹出层相关元素
        $("body", document).append("<div id=\"dialog_mask_bg\"></div><div id=\"dialog_box\"></div>");
        $("#dialog_box").append("<div id=\"dialog_box_title\"></div><div id=\"dialog_box_html\"></div><div id=\"dialog_box_bom\"></div>");

        var dialogWidth = (typeof (width) != undefined && typeof (width) == "number" && width != "") ? width : 500;
        var dialogHeight = (typeof (height) != undefined && typeof (height) == "number" && height != "") ? height : 400;
        var dialogContent = (typeof (content) != undefined && $.trim(content) != "") ? content : "";

        $("#dialog_box_title").append("<span id=\"dialog_close\">×</span>");
        $("#dialog_close").click(dialogRemove);
        $("#dialog_box_html").append(dialogContent);
        newBtn("btnOK", "确 定", clk);
        newBtn("btnCancel", "取 消");


        //取页面宽高度（兼容多浏览器及各种CSS渲染模式）
        var getSize = (function () {
            var check, obj, bodySize = [];
            var check = document.compatMode == "BackCompat" ? false : true;
            var obj = check ? document.documentElement : document.body;
            with (obj) {
                bodySize[0] = scrollWidth > clientWidth ? scrollWidth : clientWidth;
                bodySize[1] = scrollHeight > clientHeight ? scrollHeight : clientHeight;
                bodySize[2] = clientWidth;
                bodySize[3] = clientHeight;
            }
            return bodySize;
        })();

        var bodyWidth = getSize[0];
        var bodyHeight = getSize[1];
        var dialogX = (getSize[2] - dialogWidth) / 2 > 0 ? (getSize[2] - dialogWidth) / 2 : 0;
        var dialogY = (getSize[3] - dialogHeight) / 2 > 0 ? (getSize[3] - dialogHeight) / 2 : 0;

        //边框尺寸
        var dialogBorder = 1;

        //弹出层盒子显示
        $("#dialog_box").css({ "background": "#069", "position": "absolute", "border": dialogBorder + "px solid #069", "z-index": "102" })
    .css({ "left": dialogX + "px", "top": dialogY + "px", "width": dialogWidth + "px", "height": dialogHeight + "px" });

        //弹出层标题栏
        $("#dialog_box_title").css({ "width": dialogWidth + "px", "height": "25px", "color": "#FFF", "cursor": "move", "z-index": "104" })
    .css("background", "url(dialog_title_bg.gif) repeat-x top #EEE")
    .mousedown(function (e) { dialogDrag($(this).parent(), e); });

        $("#dialog_close").css({ "float": "right", "padding": "2px", "cursor": "hand", "cursor": "pointer" });


        //弹出层详细内容区
        $("#dialog_box_html").css({ "background": "#FFF", "width": dialogWidth + "px", "height": dialogHeight - 50 + "px", "z-index": "106" });

        //弹出层底部
        $("#dialog_box_bom").css({ "background": "#EEE", "width": dialogWidth + "px", "height": "25px", "z-index": "108" });


        //遮罩层背景显示
        $("#dialog_mask_bg").css({ "background": "#CCC", "position": "absolute", "opacity": "0", "z-index": "100" })
    .css({ "top": "0px", "left": "0px", "width": bodyWidth + "px", "height": bodyHeight + "px" })
    .animate({ "opacity": "0.6" }, "normal");
        bgiframe($("#dialog_mask_bg"));



        //遮罩层缩放自适应
        //$(window).resize(function(){
        //    $("#dialog_mask_bg").css({"width":"0px","height":"0px"});
        //    var reBodySize = getBodySize;
        //    $("#dialog_mask_bg").width(reBodySize[0])
        //    .height(reBodySize[1]);
        //});

        //弹出层移除
        function dialogRemove() {
            $("#dialog_mask_bg").fadeOut("fast", function () { $(this).remove(); });
            $("#dialog_box").remove();
        }

        // 创建底部按钮
        function newBtn(name, value, fn) {
            var btnObj = "<input class=\"submitMiniGreen\"  style=\"width: 124px\" type=\"button\" name=\"" + name + "\" id=\"" + name + "\" value=\"" + value + "\" />";
            var f = $.isFunction(fn) ? fn : dialogRemove;
            $("#dialog_box_bom").append(btnObj)
        .css({ "text-align": "center" });
            $("#" + name).click(f);
        }

        // 拖拽实现
        function dialogDrag(target, e) {
            var deltaX = e.clientX - target[0].offsetLeft;
            var deltaY = e.clientY - target[0].offsetTop;
            var drag = true;

            $(document).bind("mousemove", function (ev) {
                if (drag) {
                    var Y = ev.clientY - deltaY;
                    var X = ev.clientX - deltaX;
                    var H = bodyHeight - target[0].offsetHeight;
                    var W = bodyWidth - target[0].offsetWidth;
                    if (Y > 0 || X > 0) {
                        if (Y >= H) { target.css("top", H + "px"); } else { target.css("top", Y + "px"); }
                        if (X >= W) { target.css("left", W + "px"); } else { target.css("left", X + "px"); }
                    }
                    if (Y <= 0) target.css("top", "0px");
                    if (X <= 0) target.css("left", "0px");
                }
            })
        .bind("mouseup", function () {
            drag = false;
            $(this).unbind("mousemove")
            .unbind("mouseup");
        });
        }

        // 背景iframe，防select控件被遮罩无效，改自jqueryui
        function bgiframe(elm) {
            if ($.browser.msie && /6.0/.test(navigator.userAgent)) {
                html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="javascript:false;"' +
                       'style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');' +
                           'top:expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\');' +
                           'left:expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\');' +
                           'width:expression(this.parentNode.offsetWidth+\'px\');' +
                           'height:expression(this.parentNode.offsetHeight+\'px\');"/>';
                return elm.each(function () {
                    if ($('> iframe.bgiframe', this).length == 0)
                        this.insertBefore(document.createElement(html), this.firstChild);
                });
            }
            return elm;
        }

    }

})(jQuery);
///--------使用---------------------------------------------------------------------------
$(function () {
    $("#BtnYd").click(function () {
        if ($.cookie('SeatCode') == ' ' || $.cookie('SeatCode') == null) {
            alert("友情提示：请选择要预订的座位！");
        } else {
            $.dialog(540, 320, "<table id=\"TABLE1\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr><td align=\"center\" bgcolor=\"#ffffff\" colspan=\"2\" height=\"25\" style=\"color:Red\"width=\"18%\"><strong>预订客户资料</strong></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">姓 &nbsp; &nbsp; 名：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px;\"><input ID=\"t1\"  style=\"width: 250px\"/></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">联系电话：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t2\"  style=\"width: 250px\"/></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">联系地址：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t3\"  style=\"width: 250px\"/></td> </tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">单 &nbsp; &nbsp; 位：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t4\"  style=\"width: 250px\"/></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"width: 118px\"></td><td align=\"left\" bgcolor=\"#f6f6f6\" height=\"25\" style=\"width: 482px\"></td></tr></table>", okClick);
        }
    });
    $("#BtnYl").click(function () {
        if ($.cookie('SeatCode') == ' ' || $.cookie('SeatCode') == null) {
            alert("友情提示：请选择要预留的座位！");
        } else {
            $.dialog(540, 320, "<table id=\"TABLE1\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr><td align=\"center\" bgcolor=\"#ffffff\" colspan=\"2\" height=\"25\" style=\"color:Red\"width=\"18%\"><strong>预留客户资料</strong></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">姓 &nbsp; &nbsp; 名：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px;\"><input ID=\"t1\"  style=\"width: 250px\"/></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">联系电话：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t2\"  style=\"width: 250px\"/></td> </tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">联系地址：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t3\"  style=\"width: 250px\"/></td> </tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"height: 30px; width: 118px;\">单 &nbsp; &nbsp; 位：</td><td align=\"left\" bgcolor=\"#f6f6f6\" style=\"width: 482px; height: 30px\"><input ID=\"t4\"  style=\"width: 250px\"/></td></tr><tr><td align=\"center\" bgcolor=\"#f6f6f6\" style=\"width: 118px\"></td><td align=\"left\" bgcolor=\"#f6f6f6\" height=\"25\" style=\"width: 482px\"></td></tr></table>", okClick1);
        }
    });
});
    //预订
function okClick() {
    if ($("#t1").attr("value") == '' || $("#t2").attr("value") == '') {
        alert("友情提示：请填写预订人姓名和联系电话！");
    }
    else {
        if (confirm('友情提示：确定要预订你所选座位！')) {
            $('#checkFlag').show();
            $.ajax({
                type: "get",
                url: "TicketOrderHandler.axd",
                data: "SeatList=" + escape($.cookie('SeatCode')) + "&TitleCode=" + escape($("#TitleCode").val()) + "&SubCode=" + escape($("#SubCode").val()) + "&ThCode=" + escape($("#ThCode").val()) + "&UserTxt=" + escape($("#t1").attr("value")) + "&UserTel=" + escape($("#t2").attr("value")) + "&UserAddress=" + escape($("#t3").attr("value")) + "&UserUnit=" + escape($("#t4").attr("value")),
                success: function (msg) {
                    alert(msg); Reflsh();
                },
                error: function () { alert("抱歉：数据读取错误,请稍后再试!"); $('p').hide(); }
            });
            //移除层
            $("#dialog_mask_bg").fadeOut("fast", function () { $(this).remove(); });
            $("#dialog_box").remove();
        }
    } 
}
        //预留
function okClick1() {
    if ($("#t1").attr("value") == '' || $("#t2").attr("value") == '') {
        alert("友情提示：请填写预留人姓名和联系电话！");
    }
    else {
        if (confirm('友情提示：确定要预留你所选座位！')) {
            $('#checkFlag').show();
            $.ajax({
                type: "get",
                url: "TicketBookHandler.axd",
                data: "SeatList=" + escape($.cookie('SeatCode')) + "&TitleCode=" + escape($("#TitleCode").val()) + "&SubCode=" + escape($("#SubCode").val()) + "&ThCode=" + escape($("#ThCode").val()) + "&UserTxt=" + escape($("#t1").attr("value")) + "&UserTel=" + escape($("#t2").attr("value")) + "&UserAddress=" + escape($("#t3").attr("value")) + "&UserUnit=" + escape($("#t4").attr("value")),
                success: function (msg) {
                    alert(msg); Reflsh();
                },
                error: function () { alert("抱歉：数据读取错误,请稍后再试!"); $('p').hide(); }
            });
            //移除层
            $("#dialog_mask_bg").fadeOut("fast", function () { $(this).remove(); });
            $("#dialog_box").remove();
        }
    } 
}